home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48_2
/
asc.sha
/
asc.c
Wrap
C/C++ Source or Header
|
1991-04-12
|
1KB
|
53 lines
/* The crc routine is from _KERMIT_-_A_File_Transfer_Protocol_ by *
* Frank da Cruz, Digital Press, 1987. P. 257. *
* The rest is public domain; -JimC. *
* This is the final version; the 3rd to get posted. */
#include <stdio.h>
main(argc, argv)
int argc;
char **argv;
{
FILE *infile, *outfile;
int count=0, c=0, hi=0, low=0;
unsigned short value=0, dofx=0;
argc--, argv++;
if (argc > 0)
infile = fopen(*argv, "r");
else
infile = stdin;
argc--, argv++;
if (argc > 0)
outfile = fopen(*argv, "w");
else
outfile = stdout;
for (count=8; count>0; count--)
c=getc(infile);
fprintf(outfile,"%%%%HP: T(3)A(R)F(.);\n\"");
while( (c=getc(infile)) != EOF ) {
value = c;
count +=1;
dofx = (dofx >> 4) ^ (((value ^ dofx) & 0xf) * 0x1081);
dofx = (dofx >> 4) ^ ((((value >> 4) ^ dofx) & 0xf) * 0x1081);
fprintf(outfile,"%2.2X",c);
if (! (count % 32))
fprintf(outfile,"\n");
}
dofx &= 0xffff;
for (count = 1; count < 4; count++) {
fprintf(outfile,"%1.1X",dofx & 0xf);
dofx >>= 4;
}
fprintf(outfile,"\"\n");
}
/* @(#)James H. Cloos, Jr. */